package store.lunangangster.engine.impl.entity;

import java.util.HashMap;
import java.util.Map;
import store.lunangangster.engine.impl.Context;

public class TaskEntityImpl extends EntityImpl implements TaskEntity {

  // DB property
  protected String key; // TaskEntity's key <==> Task's id
  protected String executionId;
  protected String processInstanceId;
  protected String processDefinitionId;
  protected String name;
  protected String description;

  @Override
  public void setKey(String key) {
    this.key = key;
  }

  @Override
  public void setExecutionId(String executionId) {
    this.executionId = executionId;
  }

  @Override
  public void setProcessInstanceId(String processInstanceId) {
    this.processInstanceId = processInstanceId;
  }

  @Override
  public void setProcessDefinitionId(String processDefinitionId) {
    this.processDefinitionId = processDefinitionId;
  }

  @Override
  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void setDescription(String description) {
    this.description = description;
  }

  @Override
  public void addCandidateUser(String user) {
    Context.getProcessEngineConfiguration().getIdentityLinkEntityManager().addCandidateUserToTask(this, user);
  }

  @Override
  public void addCandidateGroup(String group) {
    Context.getProcessEngineConfiguration().getIdentityLinkEntityManager().addCandidateGroupToTask(this, group);
  }

  @Override
  public String getKey() {
    return key;
  }

  @Override
  public String getExecutionId() {
    return executionId;
  }

  @Override
  public String getProcessInstanceId() {
    return processInstanceId;
  }

  @Override
  public String getProcessDefinitionId() {
    return processDefinitionId;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public String getDescription() {
    return description;
  }

  @Override
  public Object getPersistState() {
    Map<String, Object> persistState = new HashMap<>();

    persistState.put("key", key);
    persistState.put("executionId", executionId);
    persistState.put("processInstanceId", processInstanceId);
    persistState.put("processDefinitionId", processDefinitionId);
    persistState.put("name", name);
    persistState.put("description", description);

    return persistState;
  }
}
